package edu.spec.sms.service.impl;

import edu.spec.sms.dao.iface.IStudentEventDao;
import edu.spec.sms.model.Student;
import edu.spec.sms.model.event.StudentEvent;
import edu.spec.sms.service.iface.IStudentEventService;
import edu.spec.sys.model.enumeration.AttendStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by MadFrog on 2017/7/16.
 */
@Service
public class StudentEventService implements IStudentEventService{

    @Autowired
    private IStudentEventDao studentEventDao;

    @Override
    public Map signIn(String openId, Integer eventId) {
        Map m = new HashMap<String, Object>();
        StudentEvent se = studentEventDao.load(openId, eventId);
        if(se==null){
            m.put("success", false);
            m.put("msg", "你别骗我，这个活动你根本没有报名!");
            return m;
        }
        se.setSignIn(1);
        studentEventDao.update(se);
        String eventName = se.getEvent().getName();
        String replay = "您对“" + eventName + "”活动，签到成功!";
        m.put("success", true);
        m.put("msg", replay);
        return m;
    }

    @Override
    public List<Student> listStudentByCon(Integer eventId, Integer clazzId, AttendStatus attendStatus) {
        return studentEventDao.listStudentByCon(eventId, clazzId, attendStatus);
    }

    @Override
    public List<Student> listAllStudentByEvent(Integer eventId) {
        List<Student> studentList = studentEventDao.listStudentByCon(eventId);
        return studentList;
    }

    @Override
    public void countAttend(Integer eventId) {
        studentEventDao.countAttend(eventId);
    }

}
